﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Abigail.Ui
{
    public partial class UiMain : Form
    {
        Controller c;
        public UiMain(Controller givenC)
        {
            InitializeComponent();
            this.Show();

            c = givenC;

            // Register eventlistener for form closing.
            this.FormClosing += UiMain_FormClosing;
        }

        private void UiMain_FormClosing(Object sender, FormClosingEventArgs e)
        {
            if (e.CloseReason == CloseReason.UserClosing)
            {
                if (Popup.QuestionYesNo("Är du säker på att du vill avsluta?", "Avsluta", "question"))
                    Controller.ExitApplication();
                else
                    e.Cancel = true;
            }
        }

        private void visaArtiklarToolStripMenuItem_Click(object sender, EventArgs e)
        {
            c.OpenUiViewArticles();
        }

        private void loggaUtToolStripMenuItem_Click(object sender, EventArgs e)
        {
            c.DoLogout();
        }

        private void avslutaToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Controller.ExitApplication();
        }

        private void minInloggningToolStripMenuItem_Click(object sender, EventArgs e)
        {
            c.OpenUiMyAccount();
        }

        private void nyInloggningToolStripMenuItem_Click(object sender, EventArgs e)
        {
            c.OpenUiNewAccount();
        }

        private void allaInloggningarToolStripMenuItem_Click(object sender, EventArgs e)
        {
            c.OpenUiAllAccounts();
        }

        private void nyNyckelToolStripMenuItem_Click(object sender, EventArgs e)
        {
            c.OpenUiNewKey();
        }

        private void visaAllaNycklarToolStripMenuItem_Click(object sender, EventArgs e)
        {
            c.OpenUiAllKeys();
        }

        private void bytLösenordToolStripMenuItem_Click(object sender, EventArgs e)
        {
            c.OpenUiEditPassword(null);
        }

        private void nyttLagerplatsområdeToolStripMenuItem_Click(object sender, EventArgs e)
        {
            c.OpenUiNewStorageLocationArea();
        }

        private void visaLagerplatsområdeToolStripMenuItem_Click(object sender, EventArgs e)
        {
            c.OpenUiViewStorageLocationAreas();
        }

        private void visaLagerplatserToolStripMenuItem_Click(object sender, EventArgs e)
        {
            c.OpenUiViewStorageLocation();
        }

        private void nyLagerplatsToolStripMenuItem_Click(object sender, EventArgs e)
        {
            c.OpenUiNewStorageLocation();
        }

        private void nyToolStripMenuItem_Click(object sender, EventArgs e)
        {
            c.OpenUiNewArticleCategory();
        }

        private void visaAllaToolStripMenuItem_Click(object sender, EventArgs e)
        {
            c.OpenUiViewArticleCategory();
        }

        private void nyArtikelToolStripMenuItem_Click(object sender, EventArgs e)
        {
            c.OpenUiNewArticle();
        }
    }
}
